<?php

/* 
 * Copyright (C) 2008 Anis uddin Ahmad <anisniit@gmail.com>
 *
 * This file is part of the "Universal Feed Writer" project.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
* 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

  include("FeedWriter/FeedTypes.php");
  include("main/inc/global.inc.php");
  //Creating an instance of RSS2FeedWriter class. 
  $TestFeed = new RSS2FeedWriter();
  
  //Setting the channel elements
  //Use wrapper functions for common channel elements
  $TestFeed->setTitle('Dokeos');
  $TestFeed->setLink(api_get_path(WEB_PATH).'index.php');
  $TestFeed->setDescription('Dokeos');
  
  //Image title and link must match with the 'title' and 'link' channel elements for valid RSS 2.0
	$TestFeed->setImage('Dokeos',api_get_path(WEB_PATH).'rss',api_get_path(WEB_PATH).'favicon.ico');
  
	$link = mysql_connect("localhost", "root", "root");

	mysql_select_db("dokeos_main", $link);

	//query announcement
	$result = mysql_query("SELECT * FROM sys_announcement", $link);

	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{

		//Create an empty FeedItem
		$newItem = $TestFeed->createNewItem();
		//Add elements to the feed item
		$newItem->setTitle($row['title']);
		$newItem->setLink(api_get_path(WEB_PATH)."newsList.php#$row[id]");
		$newItem->setDate($row['date_start']);
		$newItem->setDescription($row['content']);
		//Now add the feed item
		$TestFeed->addItem($newItem);
	}

	//$result = mysql_query("SELECT * FROM sys_announcement", $link);

	//query course
	$result = mysql_query("SELECT * FROM course", $link);
	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{

		//Create an empty FeedItem
		$newItem = $TestFeed->createNewItem();
		//Add elements to the feed item
		$newItem->setTitle($row['title']);
		$newItem->setLink(api_get_path(WEB_COURSE_PATH)."$row[code]/");
		$newItem->setDate($row['creation_date']);
		$newItem->setDescription($row['description']);
		//Now add the feed item
		$TestFeed->addItem($newItem);
	}

	//query class
	$result = mysql_query("SELECT * FROM class", $link);
	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{

		//Create an empty FeedItem
		$newItem = $TestFeed->createNewItem();
		//Add elements to the feed item
		$newItem->setTitle($row['name']);
		$newItem->setLink(api_get_path(WEB_COURSE_PATH)."$row[code]/"); // don't know the correct path to class, ignore it for now...
		//$newItem->setDate($row['creation_date']);
		$newItem->setDescription('New class is added.');
		//Now add the feed item
		$TestFeed->addItem($newItem);
	}
  //OK. Everything is done. Now genarate the feed.
  $TestFeed->generateFeed();
  
?>
